/*
 * Created on Feb 6, 2004
 */
package org.vectrics.recruiter.struts.tag;

import java.util.Collection;

import org.vectrics.common.db.DataUtils;
import org.vectrics.common.util.StringUtils;
import org.vectrics.recruiter.RecruitServiceLocator;
import org.vectrics.recruiter.config.RecruitConfig;
import org.vectrics.recruiter.user.CandidateInfo;
import org.vectrics.user.Person;
import org.vectrics.user.web.struts.UserSummaryTag;

public abstract class RecruitUserSummaryTagAbstract extends UserSummaryTag {
	
	private static final long serialVersionUID = -578220446881869023L;

	private String showResumeCount = "true";
	private String showInterviewCount = "true";
	private String showCandidateLocations = "true";

	protected void showResumeCount(Person person) {
		if ((showResumeCount.toLowerCase().startsWith("tr")) || (!this.getCompact().startsWith("t"))) {
	        Collection resumes = null;
	        if (person != null) {
	        	CandidateInfo candidate = RecruitServiceLocator.getRecruitUserService().findCandidateInfo(person);
	        	if (candidate != null) {
		            resumes = candidate.getResumes();
		        	resumes = DataUtils.removeVoided(resumes);
	        	}
	        }
	        
	        int resumeCount = 0;
	        if ((resumes == null) || (resumes.size() == 0)) {
	        } else {
	            resumeCount = resumes.size();
	        }
	        
	        this.makeFieldRow(this.getPhrase("phrase.person.resume.count"), "" + resumeCount);
		}
	}
	
    protected void showCandidateDetails(Person person) {
	    if (!this.getCompact().startsWith("t")) {
	        CandidateInfo candidateInfo = RecruitServiceLocator.getRecruitUserService().findCandidateInfo(person);
			
	        if (RecruitConfig.getRecruitInstance().getAllowJobAgents(person.getDomain())) {
		        int agentCount = 0;
		        if (candidateInfo != null) {
		            Collection agents = DataUtils.removeVoided(candidateInfo.getJobAgents()); 
		        	agentCount = agents.size(); 
		        }
		        this.makeFieldRow(this.getPhrase("phrase.person.agent.count"), "" + agentCount);
	        }
	        
	        if (candidateInfo != null) {
		        this.makeFieldRow(this.getPhrase("prompt.candidate.active"), StringUtils.capitalizeFirstLetter("" + candidateInfo.getActive()));
		        if (this.getShowInterviewCount().toLowerCase().startsWith("tr")) {
			        int interviewCount = RecruitServiceLocator.getRecruitUserService().findCandidateInterviews(candidateInfo).size();
			        this.makeFieldRow(this.getPhrase("prompt.person.interview.count"), "" + interviewCount);
		        }
		        
	        } else {
		        this.makeFieldRow(this.getPhrase("prompt.candidate.info"), this.getPhrase("phrase.person.not.candidate"));
		        this.makeFieldRow(this.getPhrase("prompt.candidate.active"), this.getPhrase("phrase.false"));
		        this.makeFieldRow(this.getPhrase("prompt.person.interview.count"), "0");
		        this.makeFieldRow(this.getPhrase("phrase.person.agent.count"), "0");
	        }
	    }
    }

    public boolean showCompany() {
    	return(false);
    }
    
    /**
	 * @return Returns the showCandidateLocations.
	 */
	public String getShowCandidateLocations() {
		return showCandidateLocations;
	}

	/**
	 * @param showCandidateLocations The showCandidateLocations to set.
	 */
	public void setShowCandidateLocations(String showCandidateLocations) {
		this.showCandidateLocations = showCandidateLocations;
	}

	protected boolean showUserPrivileges() {
    	return(false);
    }
    
	/**
	 * @return Returns the showInterviewCount.
	 */
	public String getShowInterviewCount() {
		return showInterviewCount;
	}
	/**
	 * @param showInterviewCount The showInterviewCount to set.
	 */
	public void setShowInterviewCount(String showInterviewCount) {
		this.showInterviewCount = showInterviewCount;
	}
	/**
	 * @return Returns the showResumeCount.
	 */
	public String getShowResumeCount() {
		return showResumeCount;
	}
	/**
	 * @param showResumeCount The showResumeCount to set.
	 */
	public void setShowResumeCount(String showResumeCount) {
		this.showResumeCount = showResumeCount;
	}
	
}
